home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 1999 #5 / 1999 CD 5 (black).iso / Delphi3 / DelphiNo / code.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-02-14  |  1.2 KB  |  62 lines

  1. unit code;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     LblBeskjed: TLabel;
  12.     EdtGjett: TEdit;
  13.     BtnGjett: TButton;
  14.     BtnStart: TButton;
  15.     procedure BtnStartClick(Sender: TObject);
  16.     procedure BtnGjettClick(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.     Tilfeldig: Integer;
  20.     Forsoek: Integer;
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TForm1.BtnStartClick(Sender: TObject);
  33. begin
  34.      randomize;
  35.      Tilfeldig := Random(20);
  36.      Forsoek := 0;
  37.  
  38.      LblBeskjed.Caption := 'Gjett et tall mellom 1 og 20';
  39.  
  40. end;
  41.  
  42. procedure TForm1.BtnGjettClick(Sender: TObject);
  43. var
  44.    Gjett :Integer;
  45.  
  46. begin
  47.    Gjett := StrToInt(EdtGjett.Text);
  48.    Forsoek := Forsoek + 1;
  49.  
  50.    if Gjett = Tilfeldig then
  51.         LblBeskjed.Caption := 'Du gjettet tallet i ' +
  52.                                  IntToStr(Forsoek) + '. fors°k!';
  53.  
  54.    if Gjett < Tilfeldig then
  55.       LblBeskjed.Caption := 'Tallet ' + IntToStr(Gjett) + ' er mindre enn "X"';
  56.  
  57.    if Gjett > Tilfeldig then
  58.       LblBeskjed.Caption := 'Tallet ' + IntToStr(Gjett) + ' er st°rre enn "X"';
  59. end;
  60.  
  61. end.
  62.